q = {'zero':0,
     'one':1,
     'two':2,
     'three':3,
     'four':4,
     'five':5,
     'six':6,
     'seven':7,
     'eight':8,
     'nine':9}
w = input().split()
e = int(str(q[w[0]]) + str(q[w[1]]) + str(q[w[2]]))
z, x = 0, 0
num1, num2 = e, e
if w[0] in q and w[0] != 'zero' and w[1] in q and w[2] in q and len(w) == 3:
    while e % 2 != 0 and e % 3 != 0 and e % 5 != 0 and e % 7 != 0:
        num1 += 1
        z += 1
    while e % 2 != 0 and e % 3 != 0 and e % 5 != 0 and e % 7 != 0:
        num2 -= 1
        x += 1
    if z > x:
        print(num1)
    else:
        print(num2)
else:
    print('Wrong input')